package com.rain.service.impl;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import com.rain.enums.DateTimePatternEnum;
import com.rain.utils.DateUtil;
import com.rain.enums.PageSize;
import com.rain.query.SimplePage;
import com.rain.entity.SysUser;
import com.rain.query.SysUserQuery;
import com.rain.query.PaginationResult;
import com.rain.mapper.SysUserMapper;
import com.rain.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * @auther: rain
 * @description: Service
 * @date: 2025-10-31
 */

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService{

	@Resource
	private SysUserMapper<SysUser, SysUserQuery> sysUserMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<SysUser> findListByParam(SysUserQuery query) {

		return this.sysUserMapper.selectList(query);

	}

	/**
	 * 根据条件查询数量
	 */
	public Long findCountByParam(SysUserQuery query) {

		return this.sysUserMapper.selectCount(query);

	}

	/**
	 * 分页查询
	 */
	public PaginationResult<SysUser> findListByPage(SysUserQuery query) {

		Long count = sysUserMapper.selectCount(query);
		Integer pageNo = query.getPageNo() == null ? 1 : query.getPageNo();
		Integer pageSize = query.getPageSize() == null ? PageSize.SIZE15.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), query.getPageSize(), count);
		query.setSimplePage(simplePage);
		List<SysUser> list = sysUserMapper.selectList(query);
		PaginationResult<SysUser> result = new PaginationResult(count, simplePage.getPageNo(), simplePage.getPageSize(), simplePage.getPageTotal(),list);
		return result;

	}

	/**
	 * 新增
	 */
	public Integer add(SysUser bean) {

		return sysUserMapper.insert(bean);

	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<SysUser> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return sysUserMapper.insertBatch(listBean);

	}

	/**
	 * 批量新增修改
	 */
	public Integer addOrUpdateBatch(List<SysUser> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return sysUserMapper.insertOrUpdateBatch(listBean);

	}

	/**
	 * 根据Id查询
	 */
	public SysUser getSysUserById(Integer id) {

		return sysUserMapper.selectById(id);

	}

	/**
	 * 根据Id更新
	 */
	public Integer updateSysUserById(SysUser bean, Integer id){

		return sysUserMapper.updateById(bean, id);

	}

	/**
	 * 根据Id删除
	 */
	public Integer deleteSysUserById(Integer id) {

		return sysUserMapper.deleteById(id);

	}

	/**
	 * 根据UsernameAndMobile查询
	 */
	public SysUser getSysUserByUsernameAndMobile(String username, String mobile) {

		return sysUserMapper.selectByUsernameAndMobile(username, mobile);

	}

	/**
	 * 根据UsernameAndMobile更新
	 */
	public Integer updateSysUserByUsernameAndMobile(SysUser bean, String username, String mobile){

		return sysUserMapper.updateByUsernameAndMobile(bean, username, mobile);

	}

	/**
	 * 根据UsernameAndMobile删除
	 */
	public Integer deleteSysUserByUsernameAndMobile(String username, String mobile) {

		return sysUserMapper.deleteByUsernameAndMobile(username, mobile);

	}

}